﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyNhanVien.PresentationLayer;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using QuanLyNhanVien.DataAccessLayer;
using QuanLyNhanVien.BusinessLogicLayer;
using System.IO;

namespace QuanLyNhanVien
{
    public partial class QuanLyNV : Form
    {
        NhapNhanVien nhapNhanVien;            
        NhapPhongBan nhapPhongBan;
        NhapNghiPhep nhapNghiPhep;
        InterfaceBuilder interfaceBuilder;

        public QuanLyNV()
        {
            InitializeComponent();
        }

        private void QuanLyNV_Load(object sender, EventArgs e)
        {
            //this.BackgroundImage = QuanLyNhanVien.Properties.Resources.img;
            nhapNhanVien = new QuanLyNhanVien.PresentationLayer.NhapNhanVien();
            nhapPhongBan = new QuanLyNhanVien.PresentationLayer.NhapPhongBan();
            nhapNghiPhep = new NhapNghiPhep();

            string text = "0";
            try
            {
                text = System.IO.File.ReadAllText("setting.txt");
            }
            catch (Exception ex)
            {
            }
            if (text == "1")
            {
                interfaceBuilder = new InterfaceLuongNhanVien(this);
                interfaceBuilder.BuildButton();
                interfaceBuilder.BuildBackground();
                foreach (Button button in interfaceBuilder.item.listButton)
                    this.Controls.Add(button);
                this.BackgroundImage = interfaceBuilder.item.imageBG;
                comboBox_NhomQuanLy.Text = comboBox_NhomQuanLy.Items[1].ToString();
            }
            else
            {
                interfaceBuilder = new InterfaceNhanSu(this);
                interfaceBuilder.BuildButton();
                interfaceBuilder.BuildBackground();
                foreach (Button button in interfaceBuilder.item.listButton)
                    this.Controls.Add(button);
                this.BackgroundImage = interfaceBuilder.item.imageBG;
                comboBox_NhomQuanLy.Text = comboBox_NhomQuanLy.Items[0].ToString();
            }
        }

        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ImportData import = new ImportData();
            import.Show();
        }

        private void gioiThieuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("SV thực hiện:\n\tNguyễn Văn Lê Tây (MSSV: 0912416) \n\tNguyễn Xuân Thành (MSSV: 0912426) \n\nĐây là hương trình Quản lý Nhân viên đơn giản.", "Giới thiệu");
        }

        private void thoatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void troGiupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Chương trình phiên bản 1.0 \nChương trình cho phép: \n\tThêm/ Xóa/ Sửa nhân viên - xem danh sách nhân viên. \n\tThêm/ Xóa/ Sửa phòng ban - xem danh sách phòng ban. \n\tImport data tu file XML.", "Trợ giúp.");
        }

        private void nhanVienToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Controls.Remove(nhapNhanVien);
            this.Controls.Remove(nhapPhongBan);
            this.Controls.Remove(nhapNghiPhep);
            nhapNhanVien = new QuanLyNhanVien.PresentationLayer.NhapNhanVien();            
            nhapNhanVien.Location = new System.Drawing.Point(11, 70);
            nhapNhanVien.Name = "nhapNhanVien";
            nhapNhanVien.Size = new System.Drawing.Size(878, 600);
            nhapNhanVien.TabIndex = 1;
            this.Controls.Add(nhapNhanVien);
            //FormNhapNhanVien NV = new FormNhapNhanVien();
            //NV.Show();
        }

        private void phongBanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Controls.Remove(nhapNhanVien);
            this.Controls.Remove(nhapPhongBan);
            this.Controls.Remove(nhapNghiPhep);
            nhapPhongBan = new QuanLyNhanVien.PresentationLayer.NhapPhongBan();
            nhapPhongBan.Location = new System.Drawing.Point(11, 70);
            nhapPhongBan.Name = "nhapPhongBan";
            nhapPhongBan.Size = new System.Drawing.Size(878, 600);
            nhapPhongBan.TabIndex = 1;
            this.Controls.Add(nhapPhongBan);
            
            //FormNhapPhongBan PB = new FormNhapPhongBan();
            //PB.Show();
        }

        private void nghiPhepToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Controls.Remove(nhapNhanVien);
            this.Controls.Remove(nhapPhongBan);
            this.Controls.Remove(nhapNghiPhep);
            nhapNghiPhep = new QuanLyNhanVien.PresentationLayer.NhapNghiPhep();
            nhapNghiPhep.Location = new System.Drawing.Point(11, 70);
            nhapNghiPhep.Name = "nhapPhongBan";
            nhapNghiPhep.Size = new System.Drawing.Size(878, 600);
            nhapNghiPhep.TabIndex = 1;
            this.Controls.Add(nhapNghiPhep);
        }


        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox_NhomQuanLy.SelectedIndex == 1)
            {
                this.Controls.Remove(InterfaceBuilder.nhapNhanVien);
                this.Controls.Remove(InterfaceBuilder.nhapPhongBan);
                this.Controls.Remove(InterfaceBuilder.nhapNghiPhep);

                interfaceBuilder = new InterfaceLuongNhanVien(this);
                interfaceBuilder.BuildButton();
                interfaceBuilder.BuildBackground();

                this.BackgroundImage = interfaceBuilder.item.imageBG;
                foreach (Button button in interfaceBuilder.item.listButton)
                    this.Controls.Add(button);
                System.IO.File.WriteAllText("setting.txt", "1");
            }
            else
            {
                this.Controls.Remove(InterfaceBuilder.nhapNhanVien);
                this.Controls.Remove(InterfaceBuilder.nhapPhongBan);
                this.Controls.Remove(InterfaceBuilder.nhapNghiPhep);

                interfaceBuilder = new InterfaceNhanSu(this);
                interfaceBuilder.BuildButton();
                interfaceBuilder.BuildBackground();

                this.BackgroundImage = interfaceBuilder.item.imageBG;
                foreach (Button button in interfaceBuilder.item.listButton)
                    this.Controls.Add(button);
                System.IO.File.WriteAllText("setting.txt", "0");
            }
        }

        private void button_OKURLServer_Click(object sender, EventArgs e)
        {
            ProviderCTL.SetURL(textBox_URLServer.Text);
        }

        private void button_Reset_Click(object sender, EventArgs e)
        {
            textBox_URLServer.Text = "http://localhost:7618";
            ProviderCTL.SetURL("http://localhost:7618");
        }

   }
}
